home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
733
< prev
next >
Wrap
Text File
|
1996-08-06
|
2KB
|
69 lines
Path: rover.ucs.ualberta.ca!mcbride
From: mcbride@ee.ualberta.ca (Darin McBride)
Newsgroups: comp.lang.c,comp.std.c,finet.atk.kielet.c
Subject: Re: TYPEDEF and Watcom C++ 10.5
Followup-To: comp.lang.c,comp.std.c,finet.atk.kielet.c
Date: 12 Apr 1996 19:20:43 GMT
Organization: University of Alberta Electrical Engineering Department
Distribution: world
Message-ID: <4kmaeb$10qi@pulp.ucs.ualberta.ca>
References: <4jlu1r$cs7@nic.dataphone.se>
NNTP-Posting-Host: nyquist.ee.ualberta.ca
X-Newsreader: TIN [version 1.2 PL2]
Jarmo Paavilainen (skorpio@dataphone.se) wrote:
> typedef struct
> {
> WORD CheckSum;
> WORD Version;
> BYTE PatchLevel;
> BYTE Name[21];
> WORD MarkerVersion;
> }VERSION_TAG_STRUCT;
> Shouldn't sizeof(VERSION_TAG_STRUCT) always result in 28. By other words
> shouldn't WORD always be 16 bits and BYTE 8 bits.
Usually, yes.
> If so why does my compiler claim that sizeof(VERSION_TAG_STRUCT) == 34.
> All this in 32 bit OS/2 PM and Watcom C++ 10.5
You probably have double-word alignment (i.e., pack(4)):
[ Checksum ] [ Checksum ] [ pad ] [ pad ]
[ Version ] [ Version ] [ pad ] [ pad ]
[ Patchlvl ] [ pad ] [ pad ] [ pad ]
[ Name ...... /* few lines of this until... */
[ Name ] [ pad ] [ pad ] [ pad ]
[ MarkerV ] [ MarkerV ]
Perhaps it doesn't put the padding after PatchLevel, and that would be
34 bytes.
If you require it to be 28 bytes, do the following:
#if __WATCOMC__ > 1000
#pragma pack(push,1);
#else
#pragma pack(1);
#endif
/* define struct here */
#if __WATCOMC__ > 1000
#pragma pack(pop);
#else
#pragma pack();
#endif
--
Darin McBride:mcbride@ee.ualberta.ca/mcbride@tower.bohica.net
Enjoy each day as if it were your last, care about each moment as if
it were your last for one day, one moment, you *will* be right!
Tips & Tricks for IBM Hardware, MSDOS, OS2, Windows (including Win'95):
http://www.ee.ualberta.ca/~mcbride/tiptrick.html